<template>
    <div>
        <div class="space-12"></div>
        <div class="row">
            <div class="col-xs-12">
                <div class="widget-box transparent">
                    <div class="widget-header widget-header-flat">
                        <h4 class="widget-title lighter">
                            <i class="ace-icon fa fa-bookmark"></i>
                            快捷入口
                        </h4>

                    </div>
                </div><!-- /.widget-box -->
                <div class="text-center">

                        <span class="btn btn-app btn-sm btn-primary no-hover">
                            <i class="ace-icon fa glyphicon-pencil bigger-230"></i>
                            <span class="line-height-1 smaller-90"> 企业简介 </span>
                        </span>
                    <span class="btn btn-app btn-sm btn-primary no-hover">
                            <i class="ace-icon fa glyphicon-plus bigger-230"></i>
                            <span class="line-height-1 smaller-90"> 添加产品 </span>
                        </span>
                    <span class="btn btn-app btn-sm btn-primary no-hover">
                            <i class="ace-icon fa fa-book  bigger-230"></i>
                            <span class="line-height-1 smaller-90"> 发布文章 </span>
                        </span>
                    <span class="btn btn-app btn-sm btn-primary no-hover">
                            <i class="ace-icon fa fa-share-alt bigger-230"></i>
                            <span class="line-height-1 smaller-90"> 友情链接 </span>
                        </span>
                    <span class="btn btn-app btn-sm btn-primary no-hover">
                            <i class="ace-icon fa fa-cog bigger-230"></i>
                            <span class="line-height-1 smaller-90"> 企业分站 </span>
                        </span>

                </div>

                <div class="space-12"></div>

                <div class="hr hr2 hr-double"></div>

                <div class="space-12"></div>

            </div>

            <div class="col-sm-12 infobox-container">
                <div class="infobox infobox-green">
                    <div class="infobox-icon">
                        <i class="ace-icon fa fa-comments"></i>
                    </div>

                    <div class="infobox-data">
                        <span class="infobox-data-number">0318-7179991</span>
                        <div class="infobox-content">服务热线</div>
                    </div>

                    <!--<div class="stat stat-success">8%</div>-->
                </div>

                <div class="infobox infobox-orange">
                    <div class="infobox-icon">
                        <i class="ace-icon fa fa-comments"></i>
                    </div>

                    <div class="infobox-data">
                        <span class="infobox-data-number">0318-7179991</span>
                        <div class="infobox-content">投诉热线</div>
                    </div>
                </div>

                <div class="infobox infobox-blue2">
                    <div class="infobox-icon">
                        <i class="ace-icon fa fa-comments"></i>
                    </div>

                    <div class="infobox-data">
                        <span class="infobox-data-number">微信ID：xxx</span>
                        <div class="infobox-content">微信咨询</div>
                    </div>
                </div>

                <div class="space-12"></div>

                <div class="hr hr2 hr-double"></div>

                <div class="space-12"></div>

            </div>
            <div class="text-center">
                <pagination ref="pagination" v-bind:list="list" v-bind:itemCount="8"></pagination>
                <button class="buttonFlush btn btn-bold btn-success btn-round " v-on:click="list(1)">
                    <i class="ace-icon fa fa-refresh bigger-110"></i>
                    刷新
                </button>
            </div>
            <table id="dynamic-table" class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>关键字</th>
                    <th>网址</th>
                    <th>首排</th>
                    <th>新排</th>
                    <th>变化</th>
                    <th>添加时间</th>
                    <!--<th class="hidden-480">操作</th>-->
                </tr>
                </thead>

                <tbody>
                <tr v-for="user in users" :key="user.index">
                    <td>{{user.id}}</td>
                    <td>
                        <div class="action-buttons">
                            <a href="#" class="blue bigger-110 show-details-btn" title="Show Details"
                               v-on:click="edit(user)"
                            >
                                <i class="ace-icon fa fa-angle-double-down">&nbsp;{{user.keyword}}</i>
                                <span class="sr-only"></span>
                            </a>
                        </div>
                    </td>
                    <td>{{user.url}}</td>
                    <td>{{user.first_ranking}}</td>

                    <td>
                        {{user.new_ranking}}
                        <!--<div class="hidden-sm hidden-xs btn-group">
                            <button v-show="getUserResources('010103')" class="btn btn-xs btn-info" v-on:click="edit(user)">
                                <i class="ace-icon fa fa-pencil bigger-120">&nbsp;编辑用户</i>
                            </button>
                            <button v-show="getUserResources('010101')" class="btn btn-xs btn-success" v-on:click="editPWD(user)">
                                <i class="ace-icon fa fa-key bigger-120">&nbsp;修改密码</i>
                            </button>
                            <button v-show="getUserResources('010102')" class="btn btn-xs btn-danger" v-on:click="del(user.id)">
                                <i class="ace-icon fa fa-trash-o bigger-120">&nbsp;删除</i>
                            </button>
                        </div>

                        <div class="hidden-md hidden-lg">
                            <div class="inner pos-rel">
                                <button class="btn btn-minier btn-primary dropdown-toggle"
                                        data-toggle="dropdown" data-position="auto">
                                    1
                                    <i class="ace-icon fa fa-cog icon-only bigger-120"></i>
                                </button>
                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                    <li>
                                        <a href="#" class="tooltip-info" data-rel="tooltip" title="view"
                                           v-on:click="edit(user)">
                                        <span class="blue">
                                            <i class="ace-icon fa fa-pencil bigger-120"></i>
                                        </span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#" class="tooltip-info" data-rel="tooltip" title="view"
                                           v-on:click="del(user.id)">
                                        <span class="blue">
                                            <i class="ace-icon fa fa-trash bigger-120"></i>
                                        </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>-->
                    </td>
                    <td>
                        暂无内容
                    </td>
                    <td>
                        {{user.create_time_format}}
                    </td>
                </tr>

                </tbody>
            </table>

            <div id="form-modal" class="modal fade" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">周期排名数据</h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">关键字</label>
                                    <div class="col-sm-10">
                                        <!--bind事件：如果user.id有值，=true=disabled-->
                                        <input v-bind:disabled="user.id"
                                               v-model="user.keyword"
                                               type="text" class="form-control"
                                               placeholder="登录名">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">网址</label>
                                    <div class="col-sm-10">
                                        <input
                                                v-model="user.url"
                                                type="text" class="form-control"
                                                placeholder="昵称">
                                    </div>
                                </div>

                                <!--如果id有值，则不显示密码编辑-->
                                <div v-show="!user.id" class="form-group">
                                    <label class="col-sm-2 control-label">密码</label>
                                    <div class="col-sm-10">
                                        <input
                                                v-model="user.nickName" type="password"
                                                class="form-control"
                                                placeholder="密码">
                                    </div>
                                </div>

                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" v-on:click="save()">保存</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->

            <!--修改密码模态框-->
            <div id="edit-password-modal" class="modal fade" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <h4 class="modal-title">修改密码</h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <label class="control-label col-lg-3">密码</label>
                                    <div class="col-lg-9">
                                        <input class="form-control" type="password" v-model="user.password"
                                               name="password">
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-round" data-dismiss="modal">
                                <i class="ace-icon fa fa-times"></i>
                                取消
                            </button>
                            <button type="button" class="btn btn-primary btn-round" v-on:click="savePWD()">
                                <i class="ace-icon fa fa-plus-circle"></i>
                                保存
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-sm-12">
                <div class="widget-box transparent">
                    <div class="widget-header widget-header-flat">
                        <h4 class="widget-title lighter">
                            <i class="ace-icon fa fa-signal"></i>
                            竞价排名图
                        </h4>

                    </div>

                    <div class="widget-body">
                        <div class="widget-main padding-4">
                            <div id="sales-charts"></div>
                        </div><!-- /.widget-main -->
                    </div><!-- /.widget-body -->
                </div><!-- /.widget-box -->

                <div class="space-12"></div>

                <div class="hr hr2 hr-double"></div>

                <div class="space-12"></div>
            </div><!-- /.col -->


        </div><!-- /.row -->

    </div>
</template>

<script>
    import Pagination from "../../components/pagination";

    export default {
        name: "welcome",
        components: {Pagination},
        data: function () {
            return {
                user: {},
                users: [],
            }
        },
        mounted: function () {
            let _this = this;
            //设置了admin的跳转及子路由跳转，这里可取消
            this.$parent.activeSidebar("welcome-sidebar");
            _this.drawSaleChart();

            //分页
            _this.$refs.pagination.size = 10;
            _this.list(1);
        },
        methods: {
            drawSaleChart() {
                // 生成随机两组数据
                let d1 = [];
                for (let i = 0; i < 30; i += 1) {
                    d1.push([i + 1, 2000 + Math.floor((Math.random() * 100) + 1)]);
                }
                let d2 = [];
                for (let i = 0; i < 30; i += 1) {
                    d2.push([i + 1, 1900 + Math.floor((Math.random() * 100) + 1)]);
                }

                let sales_charts = $('#sales-charts').css({'width': '100%', 'height': '220px'});
                $.plot("#sales-charts", [
                    {label: "最近30天", data: d1},
                    {label: "上一周期", data: d2},
                ], {
                    hoverable: true,
                    shadowSize: 0,
                    series: {
                        lines: {show: true},
                        points: {show: true}
                    },
                    xaxis: {
                        tickLength: 0
                    },
                    yaxis: {
                        tickLength: 0
                    },
                    grid: {
                        backgroundColor: {colors: ["#fff", "#fff"]},
                        borderWidth: 1,
                        borderColor: '#555'
                    }
                });
            },

            //user列
            //调取tool方法
            getUserResources(id) {
                return Tool.getUserResources(id);
            },
            /**
             * 列表查询
             */
            list(page) {
                let _this = this;
                Loading.show();
                //_this.$ajax.post(process.env.VUE_APP_SERVER + '/system/admin/user/list',
                _this.$ajax.post('http://pm.seo.xchost.cn/keyword/getList',
                    /*{
                        currentPage: page,
                        initPageNum: _this.$refs.pagination.size
                    }).then((responseDTO) => {
                    Loading.hide();
                    console.log("查询用户表列表：", responseDTO);
                    let resp = responseDTO.data;
                    _this.users = resp.responseData.list;
                    _this.$refs.pagination.render(page, resp.responseData.sumPage);
                })*/
                    {
                        curr: page,
                        row: _this.$refs.pagination.size
                    }).then((body) => {
                    Loading.hide();
                    console.log("查询用户表列表：", body);
                    let resp = body.data;
                    _this.users = resp.body.list;
                    _this.$refs.pagination.render(page, resp.body.count);
                })
            },
            /**
             * 点击【新增】
             */
            add() {
                let _this = this;
                console.log("为不引起eslint提醒，调用_list:" + _this);
                _this.user = {};
                $("#form-modal").modal("show");

            },
            /**
             * 点击【保存】
             */
            save() {
                let _this = this;

                //保存校验，1!=1去掉自动生成的代码第一个||或
                if (1 != 1
                    || !Validator.require(_this.user.loginName, "登录名")
                    || !Validator.length(_this.user.loginName, "登录名", 3, 50)
                    || !Validator.length(_this.user.nickName, "昵称", 3, 50)
                    || !Validator.require(_this.user.password, "密码")
                ) {
                    return;
                }
                //密码加密+盐值
                _this.user.password = hex_md5(_this.user.password + KEY);
                Loading.show();
                _this.$ajax.post(process.env.VUE_APP_SERVER + '/system/admin/user/save', _this.user)
                    .then((responseAdd) => {
                        Loading.hide();
                        console.log("保存用户表结果：", responseAdd);
                        let resp = responseAdd.data;
                        if (resp.success) {
                            $("#form-modal").modal('hide');
                            _this.list(1);
                            //添加提示
                            Toast.success("保存成功！");
                        } else {
                            console.log("走到这里了！");
                            Toast.warning(resp.responseMsg);
                        }
                    })
            },
            /**
             * 点击【编辑】
             */
            edit(user) {
                let _this = this;

                _this.user = $.extend({}, user);
                $("#form-modal").modal("show");

                Loading.show();
                //_this.$ajax.post(process.env.VUE_APP_SERVER + '/system/admin/user/list',
                _this.$ajax.post('http://pm.seo.xchost.cn/keyword/getRankingList',
                    /*{
                        currentPage: page,
                        initPageNum: _this.$refs.pagination.size
                    }).then((responseDTO) => {
                    Loading.hide();
                    console.log("查询用户表列表：", responseDTO);
                    let resp = responseDTO.data;
                    _this.users = resp.responseData.list;
                    _this.$refs.pagination.render(page, resp.responseData.sumPage);
                })*/
                    {
                        id: _this.user.id,
                        time: _this.user.time
                    }).then((body) => {
                    Loading.hide();
                    console.log("查询用户表列表：", body);
                    let resp = body.data;
                    //_this.users = resp.body.list;
                    /*_this.$refs.pagination.render(page, resp.body.count);*/
                })
            },
            /**
             * 点击【删除】
             */
            del(id) {
                let _this = this;
                Confirm.show("删除用户表后不可恢复!", function () {
                    Loading.show();
                    _this.$ajax.delete(process.env.VUE_APP_SERVER + '/system/admin/user/delete/' + id)
                        .then((responseDel) => {
                            Loading.hide();
                            console.log("删除用户表内容：", responseDel);
                            let resp = responseDel.data;
                            if (resp.success) {
                                _this.list(1);
                                Toast.success("删除成功！");
                            }
                        });
                });
            },
            /**
             * 修改密码
             */
            editPWD(user) {
                let _this = this;
                _this.user = $.extend({}, user);
                //打开编辑清空数据
                _this.user.password = null;
                $("#edit-password-modal").modal("show");
            },
            /**
             * 保存密码
             */
            savePWD() {
                let _this = this;

                //密码加密+盐值
                _this.user.password = hex_md5(_this.user.password + KEY);
                Loading.show();
                _this.$ajax.post(process.env.VUE_APP_SERVER + '/system/admin/user/save-pwd', _this.user)
                    .then((responseAdd) => {
                        Loading.hide();
                        console.log("保存用户表结果：", responseAdd);
                        let resp = responseAdd.data;
                        if (resp.success) {
                            $("#form-modal").modal('hide');
                            _this.list(1);
                            //添加提示
                            Toast.success("保存成功！");
                            $("#edit-password-modal").modal("hide");
                        } else {
                            Toast.warning(resp.responseMsg);
                        }
                    })
            },

        }
    }

</script>

<style scoped>
    .text-center {
        padding-bottom: 10px;
    }

    .buttonFlush {
        margin-bottom: 12px;
        margin-left: 10px;
    }
</style>